<?php

namespace App\Controller\Common;

use App\Base\BaseCache;
use App\Base\BaseController;
use App\Setting\AdminUserSetting;
use BaseExt\Captcha;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;

class AutoMenuController extends BaseController
{
    /**
     * @route("/amc",name="AutoMenuCreate")
     */
    public function AutoMenuCreate(Request $request)
    {
        $doctrine = $this->getDoctrine();
        $dirEntity = __DIR__."\..\..\Setting\\";
        //查找Entity
        if (!is_dir($dirEntity)) {
            $dirEntity = __DIR__."/../../Setting/";
        }
        $entityList = scandir($dirEntity);
        $menu = [];
        foreach ($entityList as $item) {
            $array = mb_split("\.",$item);
            if ($array[count($array) - 1] != "php") {
                continue;
            }
            $itemName = $array[0];
            $entityName = "App\Setting\\".$itemName;
            $entity = new $entityName($doctrine);
            /**@var $entity AdminUserSetting*/
            $group = $entity->catType;
            $name = $entity->entityCnName;
            $en = $entity->table;
            $menu[] = [
                "name" => $en,
                "group" => $group,
                "title" => $name . $en
            ];
        }
        $bc = new BaseCache();
        $bc->setItem('initMenu',$menu);
        dd($menu);
    }

}
